﻿Public Class dlgAreaPolySource

    Private Sub txtRelhgt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRelhgt.TextChanged

    End Sub

    Private Sub txtRelhgt_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtRelhgt.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).Relhgt = Me.txtRelhgt.Value
        Next
    End Sub

    Private Sub txtSzinit_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSzinit.Validating
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).Szinit = Me.txtSzinit.Value
        Next
    End Sub

    Private Sub txtVertsCounts_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtVertsCounts.Validating
        Me.EFlexNVerts.Rows.Count = Me.txtVertsCounts.Value + 1
        For i As Integer = 1 To Me.txtVertsCounts.Value
            EFlexNVerts.SetData(i, 0, i)
        Next
        EFlexNVerts_Validating(sender, e)
    End Sub

    Private Sub EFlexNVerts_AfterEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles EFlexNVerts.AfterEdit
        txtXs.Value = Me.EFlexNVerts.GetData(1, 1)
        txtYs.Value = Me.EFlexNVerts.GetData(1, 2)
    End Sub

    Private Sub EFlexNVerts_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EFlexNVerts.Validating
        '设置第一个点
        Dim V(Me.txtVertsCounts.Value - 2) As Point
        For n As Integer = 0 To Me.txtVertsCounts.Value - 2
            V(n) = New Point
            V(n).X = Me.EFlexNVerts.GetData(n + 2, 1)
            V(n).Y = Me.EFlexNVerts.GetData(n + 2, 2)
        Next
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            '设置顶点
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).Location.Xs = Me.EFlexNVerts.GetData(1, 1)
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).Location.Ys = Me.EFlexNVerts.GetData(1, 2)
            '设置其它顶点
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).SetVerts(V)
        Next
    End Sub

    Private Sub ListPolute_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListPolute.SelectedIndexChanged
        If Me.ListPolute.SelectedIndex >= 0 Then
            Me.txtRelhgt.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).Relhgt
            Me.txtSzinit.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).Szinit
            Me.txtVertsCounts.Value = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).NvertsCounts + 1 '顶点个数为其它顶点数加1
            Me.EFlexNVerts.Rows.Count = Me.txtVertsCounts.Value + 1
            '设置第一个点
            Me.EFlexNVerts.SetData(1, 1, CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).Location.Xs)
            Me.EFlexNVerts.SetData(1, 2, CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).Location.Ys)
            Dim V(Me.txtVertsCounts.Value - 2) As Point
            V = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).GetVerts
            For n As Integer = 0 To Me.txtVertsCounts.Value - 2
                Me.EFlexNVerts.SetData(n + 2, 1, V(n).X)
                Me.EFlexNVerts.SetData(n + 2, 2, V(n).Y)
            Next
            '设置顶点序号
            For i As Integer = 1 To Me.txtVertsCounts.Value
                EFlexNVerts.SetData(i, 0, i)
            Next
            Me.cmbPolluteUnit.Text = CType(Me.BaseSoruce(ListPolute.SelectedIndex), CAermod.AreaPolySource).PolluteUnit
        End If
    End Sub

    Private Sub dlgAeraPolySource_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EFlexEmisFact.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexMethod1.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexNVerts.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.EFlexSourceNameAndS.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        Me.txtXs.Enabled = False
        Me.txtYs.Enabled = False
        Me.EFlexSourceNameAndS.SetData(0, 1, "排放速率")

        Me.EFlexEmisFact.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexEmisFact.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexEmisFact.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexMethod1.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexMethod1.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexMethod1.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexNVerts.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexNVerts.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexNVerts.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None

        Me.EFlexSourceNameAndS.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        Me.EFlexSourceNameAndS.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.None
        Me.EFlexSourceNameAndS.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
    End Sub

    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        Dim AreaPolySource(-1) As CAermod.AreaPolySource
        AreaPolySource = Me.m_BaseSoruce
        ReDim Preserve AreaPolySource(AreaPolySource.Length)
        AreaPolySource(AreaPolySource.Length - 1) = New CAermod.AreaPolySource
        ReDim AreaPolySource(AreaPolySource.Length - 1).PollutionPara(Me.m_ArrayPollut.Length - 1) '设置新增加的污染源的污染物的类型
        AreaPolySource(AreaPolySource.Length - 1).PollutionPara(Me.m_ArrayPollut.Length - 1) = New CAermod.PollutionPara
        AreaPolySource(AreaPolySource.Length - 1).SetPollutePara(AermodProject0.Aermod.Control.AllPolluts)
        AreaPolySource(AreaPolySource.Length - 1).Location.Srcid = "AP" & (Me.m_SourceCount + 1)
        Me.m_SourceCount += 1
        AreaPolySource(AreaPolySource.Length - 1).SourceName = "多边形面源" & m_SourceCount '污染源名称

        Me.m_BaseSoruce = AreaPolySource
        ''修改列表
        Me.ListPolute.Items.Add(AreaPolySource(AreaPolySource.Length - 1).SourceName)

        ListPolute.SelectedIndex = ListPolute.Items.Count - 1
    End Sub

    Private Sub txtVertsCounts_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtVertsCounts.TextChanged

    End Sub

    Private Sub EFlexNVerts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EFlexNVerts.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDel.Click
        Dim iSelected As Integer = ListPolute.SelectedIndex
        If iSelected >= 0 Then
            Dim AreaPolySources(-1) As CAermod.AreaPolySource
            AreaPolySources = Me.m_BaseSoruce
            If iSelected <= ListPolute.Items.Count - 2 Then
                For i As Integer = iSelected To ListPolute.Items.Count - 2
                    AreaPolySources(i) = AreaPolySources(i + 1)

                Next
            End If
            ReDim Preserve AreaPolySources(AreaPolySources.Length - 2)
            ListPolute.Items.Clear()
            For i As Integer = 0 To AreaPolySources.Length - 1
                ListPolute.Items.Add(AreaPolySources(i).SourceName)
            Next
            If ListPolute.Items.Count > 0 Then
                If iSelected <= ListPolute.Items.Count - 1 Then
                    ListPolute.SelectedIndex = iSelected
                Else
                    ListPolute.SelectedIndex = iSelected - 1
                End If
            End If

            Me.m_BaseSoruce = AreaPolySources
        End If
    End Sub

    Private Sub cmbPolluteUnit_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPolluteUnit.SelectedIndexChanged
        Dim i As Integer
        For i = 0 To Me.ListPolute.SelectedItems.Count - 1
            CType(Me.BaseSoruce(ListPolute.SelectedIndices(i)), CAermod.AreaPolySource).PolluteUnit = Me.cmbPolluteUnit.Text
        Next
    End Sub
    Public Sub Modify()
        Dim p As New Point
        p.X = Me.Location.X
        p.Y = Me.UltraTabControl3.Location.Y
        Me.UltraTabControl3.Location = p
        Me.cmdAdd.Visible = False
        Me.cmdDel.Visible = False
        Me.Width = 500
    End Sub
End Class
